package com.loveyukari.dao;

import com.loveyukari.dao.impl.BaseDao;
import org.springframework.jdbc.core.BatchPreparedStatementSetter;
import org.springframework.stereotype.Repository;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Repository
public class TmpDao  extends BaseDao{



    public Set<Integer> selectAuthId(String group){
        String sql = "select auth_id from draw_exclude where type = ?";
        List<Integer> list = this.getJdbcTemplate().queryForList(sql, Integer.class, group);
        return new HashSet<>(list);
    }

    public void insertbatchDrawExclude(final String group, final List<Integer> authIds){
        String sql = "insert into draw_exclude (type,auth_id,create_time) values (?,?,?)";
        final Timestamp createTime = new Timestamp(new Date().getTime());
        this.getJdbcTemplate().batchUpdate(sql, new BatchPreparedStatementSetter() {
            @Override
            public void setValues(PreparedStatement ps, int i) throws SQLException {
                ps.setString(1,group);
                ps.setInt(2,authIds.get(i));
                ps.setTimestamp(3,createTime);
            }

            @Override
            public int getBatchSize() {
                return authIds.size();
            }
        });
    }



}
